package ctl

import (
	"dynamic-private/internal/service"
	"dynamic-private/pkg/dto"

	"github.com/gin-gonic/gin"
	"github.com/tristin2024/logs"
	"github.com/tristin2024/render"
	"github.com/tristin2024/validate"
)

// 方法名与路由处保持一致
/*func RoomInfo(c *gin.Context) {
	var req dto.RoomInfo
	if err := c.ShouldBindJSON(&req); err != nil {
		render.ErrBadRequest(c, "参数类型错误")
		return
	}
	if err := validate.Struct(&req); err != nil {
		logs.Std.Warn(err)
		render.ErrBadRequest(c, "参数校验失败")
		return
	}

	data, err := service.RoomService.GetRoomInfo(&req)
	if err != nil {
		logs.Std.Error(req, err)
		render.ErrBadRequest(c, "获取房间信息失败")
		return
	}
	render.Data(c, data.Data, "获取成功")
}*/

// QueryPostAndCountByUserId 根据用户Id返回动态总数和五条动态
func QueryPostAndCountByUserId(c *gin.Context) {
	var req dto.QueryPostAndCountByUserId
	if err := c.ShouldBindJSON(&req); err != nil {
		render.ErrBadRequest(c, "参数类型错误")
		return
	}
	if err := validate.Struct(&req); err != nil {
		logs.Std.Warn(err)
		render.ErrBadRequest(c, "参数校验失败")
		return
	}

	data, err := service.DynamicService.QueryPostAndCountByUserId(&req)
	if err != nil {
		logs.Std.Error(req, err)
		render.ErrBadRequest(c, "获取动态信息失败")
		return
	}
	render.Data(c, data, "获取成功")
}

// QueryPostAndCountByUserIds 根据用户id切片返回动态总数和五条动态
func QueryPostAndCountByUserIds(c *gin.Context) {
	var req dto.QueryPostAndCountByUserIds
	if err := c.ShouldBindJSON(&req); err != nil {
		render.ErrBadRequest(c, "参数类型错误")
		return
	}
	if err := validate.Struct(&req); err != nil {
		logs.Std.Warn(err)
		render.ErrBadRequest(c, "参数校验失败")
		return
	}
	data, err := service.DynamicService.QueryPostAndCountByUserIds(&req)
	if err != nil {
		logs.Std.Error(req, err)
		render.ErrBadRequest(c, "获取动态信息失败")
		return
	}
	render.Data(c, data, "获取成功")
}

// QueryPostDetailByPostId 根据动态id返回动态详情
func QueryPostDetailByPostId(c *gin.Context) {
	var req dto.QueryPostDetailByPostId
	if err := c.ShouldBindJSON(&req); err != nil {
		render.ErrBadRequest(c, "参数类型错误")
		return
	}
	if err := validate.Struct(&req); err != nil {
		logs.Std.Warn(err)
		render.ErrBadRequest(c, "参数校验失败")
		return
	}
	data, err := service.DynamicService.QueryPostDetailByPostId(&req)
	if err != nil {
		logs.Std.Error(req, err)
		render.ErrBadRequest(c, "获取动态详情失败")
		return
	}
	render.Data(c, data, "获取成功")
}
